@extends('admin.layout.layout')
@section('title','商品帖子列表')
@section('con')
<div id="page-wrapper" style="min-height: 349px;">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">商品帖子列表</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    商品帖子列表
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="dataTable_wrapper">
                        <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                            <div class="row">
                                <form action="{{url('/admin/gposts/index')}}">
	                                <div class="col-sm-6">
		                                <div id="dataTables-example_filter" class="dataTables_filter">
			                                <label>搜索:
			                                	<input name="keywords" value="{{ $list['keywords'] or '' }}" type="search" class="form-control input-sm" placeholder="请输标题作者或关键字" aria-controls="dataTables-example" />
			                                </label>
			                                <button class="btn btn-sm btn-primary" >查询</button>
		                               	</div>
	                                </div>
                                 </form>
                            </div>
                            <div class="row">
                            	<div class="col-sm-12">
                            		<table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info" style="font-size:13px">
                                		<thead>
                                			<tr>
	                                    		<th>帖子ID</th>
	                                    		<th>标题<span style="color:#cccccc;font-size:12px">(点击标题显示详情)</span></th>
	                                    		<th>作者</th>
	                                    		<th>关键字</th>
	                                    		<th>浏览量</th>
	                                    		<th>创建时间</th>
	                                    		<th>修改时间</th>
	                                    		<th>状态</th>
	                                    		<th>操作</th>
                                			</tr>
                                		</thead>
                                    	<tbody>
                                    		@foreach($gposts as $k=>$v)
		                                    <tr class="gradeA odd" role="row">
		                                        <td class="sorting_1 gpid">{{$v->gpid}}</td>
		                                        <td class="center title" data-toggle="modal" data-target=".bs-example-modal-lg_{{$v->gpid}}"><div style="width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">{{$v->gptitle}}</div></td>
		                                        <td class="center">{{$v->username}}</td>
		                                        <td class="center">{{$v->gpoint}}</td>
		                                        <td class="center">{{$v->gpview}}</td>
		                                        <td class="center">{{$v->gpctime}}</td>
		                                        <td class="center">{{$v->gputime}}</td>
		                                        <td class="center"><button class="btn btn-default status" type="button">{{$v->gpstatus}}</button></td>
		                                        <td class="center">
				                                	<a href="/admin/gposts/edit?gpid={{$v->gpid}}" class="btn btn-outline btn-primary" type="button">修改</a>
		                                        </td>
		                                    </tr>
											
		                                    <!-- 详情 模态框 -->
											<div class="modal fade bs-example-modal-lg_{{$v->gpid}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
												<div class="modal-dialog modal-lg">
													<div class="modal-content">
														<div class="modal-header">
															<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
															<h4 class="modal-title" id="myModalLabel">帖子详情</h4>
														</div>
														<div class="modal-body">
															<div class="row">
										                        <div class="col-lg-12">
										                        	<!-- 标题 -->
										                        	<h4>{{$v->gptitle}}</h4><br>
										                        	<!-- 发帖用户及时间 -->
										                        	<div style="text-align:right;color:grey;">由用户&nbsp;<span style="color:blue">{{$v->username}}</span>&nbsp;,于&nbsp;{{$v->gpctime}}&nbsp;发表</div><br>
										                        	<!-- 商品帖子内容 -->
										                        	<div>{!! $v->gpcont !!}</div>
										                    	</div>
										                    	<div class="col-lg-12" style="border-top:1px solid #E5E5E5">
										                    		<!-- 评论数 -->
										                        	<div style="text-align:right;color:grey;">共&nbsp;<span class="gcnum" style="color:blue"></span>&nbsp;条评论</div>
										                    		<!-- 评论区 -->
										                    		<div class="plq">

										                    		</div>
										                    	</div>
															</div>
														</div>
													<div class="modal-footer">	
														<!-- <a href="" class="btn btn-outline btn-primary" target="_blank" >直达帖子链接</a> -->
													</div>
												</div>
											</div>			
		                                    <!-- 模态框 -->
											@endforeach
		                                   
                                    	</tbody>
                            		</table>
                            	</div>
                            </div>
                            <!-- 分页 -->
                            <div class="row">
	                   			<div style="margin:0px auto">
	                   				{!! $gposts->appends($list)->render() !!}
	                   			</div>
	                   		</div>
                        </div>
                	</div>
            	</div>
        	</div>
    	</div>
	</div>
</div>
@endsection
@section('js')
<script type="text/javascript">

	
	
	// 绑定单击事件 发送 ajax 查询帖子详情
	$('.title').click(function(){
		var gpid = $(this).prev().html();  //获取帖子id	
		$.ajax({
            url:'{{url('/admin/gposts/detailcheck')}}',
            data:{gpid:gpid},
            type:'get',
            success:function(data){
                eval('var pl = '+data);
                $('.gcnum').html(pl.length);
			    var str = '';
			    for (var i = 0; i < pl.length; i++) {
			    	str += "<div class='gcs' style='border-bottom:1px solid #E5E5E5'><div>用户:&nbsp;"+pl[i].username+"</div><div style='text-indent:30px;'>"+pl[i].gpcont+"</div><div style='font-size:13px;color:#999999'>发表于&nbsp;"+pl[i].gpctime+"</div></div>"
			    	$('.plq').html(str);
				};
            },
            error:function(){
                console.log('ajax错误');
            },
            timeout:3000,
            async:false
        })
	})


	// 绑定双击事件修改状态
	$('.status').dblclick(function(){
		var gpstatus = $(this).html();  //获取状态
		var gpid = $(this).parents('tr').find('.gpid').html();  //获取帖子id	
		var a = $(this);

		$.get('/admin/gposts/cstatus',{gpstatus:gpstatus,gpid:gpid},function(data){
			eval('status = '+data);

			a.html(status); //修改内容
			
		})
	})
	

</script>
@endsection









